package com.khshop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khshop.mapper.CollectMapper;
import com.khshop.pojo.Collect;
import com.khshop.mapper.CollectMapper;
import com.khshop.pojo.Collect;
import com.khshop.service.CollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.khshop.vo.ServiceResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 收藏 服务实现类
 * </p>
 *
 * @author zhaoyang
 * @since 2020-10-16
 */
@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect> implements CollectService {

    @Autowired(required = false)
    CollectMapper collectMapper;

    //新增收藏
    public ServiceResult<Collect> addCollect(Collect collect){
        return ServiceResult.of(collectMapper.insert(collect)>0);

    }

    //修改收藏
    public ServiceResult<Collect> updateCollect(Collect collect){
        return ServiceResult.of(collectMapper.updateById(collect)>0);

    }

    //删除收藏
    public ServiceResult<Collect> delCollect(Integer id){
        return ServiceResult.of(collectMapper.deleteById(id)>0);

    }


    //查询收藏
    public ServiceResult<IPage<Collect>> searchCollect(Map<String,String> map, Integer page, Integer limit){
        QueryWrapper<Collect> queryWrapper = new QueryWrapper<>();
        queryWrapper.allEq(map);
        Page<Collect> iPage = new Page<Collect>(page, limit);
        IPage<Collect> orderIPage = collectMapper.selectPage(iPage, queryWrapper);
        return ServiceResult.of(orderIPage,orderIPage.getSize()>0);

    }
}
